package treasurer;

import home.HomePage;

import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;
import java.util.List;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

import controllers.BKPayroll;
import controllers.BKPayrollSub;
import controllers.BKSubsidiary;

public class PayrollSubList extends WebPage {
	
	public PayrollSubList() throws IOException, SQLException
	{
		Reader reader = Resources.getResourceAsReader("sqlMapConfig.xml");
		SqlMapClient sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
		
		add(new BookmarkablePageLink("home", TreasurerHome.class));
		add(new BookmarkablePageLink("logoutPage", HomePage.class));
		add(new BookmarkablePageLink("addRecipient", PayrollSub.class));
		
		Form form = new Form("PayrollSubListForm");
		
		List<BKPayrollSub> list = (List<BKPayrollSub>)sqlMap.queryForList("BKPayrollSub.getAll");
		
		ListView eachRecord = new ListView("eachRecord", list) {
			private static final long serialVersionUID = 1L;
			
			protected void populateItem(ListItem item) {
				final BKPayrollSub bkp = (BKPayrollSub) item.getModelObject();
				
				item.add(new Label("payee", bkp.getPayee()));
				item.add(new Label("dateRec", bkp.getDateRec()));
				item.add(new Label("amount", Float.toString(bkp.getAmount())));
				
			}
		};
		
		add(new BookmarkablePageLink("payrollList", Payroll.class));
		form.add(eachRecord);
		add(form);
	}

}
